import { resolve } from "path";
import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from "electron-vite";
import vue from "@vitejs/plugin-vue";
// Element Plus
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin(), bytecodePlugin()]
  },
  renderer: {
    resolve: {
      alias: {
        "@renderer": resolve("src/renderer/src"),
        "@router": resolve("src/renderer/src/router"),
        "@/views": resolve("src/renderer/src/views"),
        "@/utils": resolve("src/renderer/src/utils"),
        "@/store": resolve("src/renderer/src/store"),
        "@/assets": resolve("src/renderer/src/assets"),
        "@/login": resolve("src/renderer/src/views/login"),
        "@/hooks": resolve("src/renderer/src/hooks"),
        "@/api": resolve("src/renderer/src/api"),
        "@/interface": resolve("src/renderer/src/interface"),
        "@/layout": resolve("src/renderer/src/layout"),
      }
    },
    server: {
      proxy: {
        "/api": {
          target: "http://uat.crm.xuexiluxian.cn",
          changeOrigin: true,
          rewrite(path) {
            return path.replace(/^\/api/, "");
          }
        }
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          silenceDeprecations: ['legacy-js-api']
        },
      },
    },
    plugins: [
      vue(),
      AutoImport({
        resolvers: [ElementPlusResolver()]
      }),
      Components({
        resolvers: [ElementPlusResolver()]
      }),
    ]
  },
});
